import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.resps.Tuple;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2025-03-30
 * Time: 14:53
 */
public class RedisDemoZSet {
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");

        /*try (Jedis jedis = jedisPool.getResource()) {
            System.out.println("zadd 和 zrange 的使用");
            jedis.flushAll();

            jedis.zadd("key1",10,"zhangsan");
            Map<String,Double> map = new HashMap<>();
            map.put("lisi",20.0);
            map.put("wangwu",30.0);
            jedis.zadd("key1",map);

            List<String> result = jedis.zrange("key1",0,-1);
            System.out.println("result: " + result);

            List<Tuple>result1 = jedis.zrangeWithScores("key1",0,-1);
            System.out.println("result1: " + result1);
        }*/

        /*try (Jedis jedis = jedisPool.getResource()) {
            System.out.println("zcard 的使用");
            jedis.flushAll();

            jedis.zadd("key1",10,"zhangsan");
            Map<String,Double> map = new HashMap<>();
            map.put("lisi",20.0);
            map.put("wangwu",30.0);
            jedis.zadd("key1",map);

            long result = jedis.zcard("key1");
            System.out.println("result: " + result);


        }*/

        /*try (Jedis jedis = jedisPool.getResource()) {
            System.out.println("zrem 的使用");
            jedis.flushAll();

            jedis.zadd("key1",10,"zhangsan");
            Map<String,Double> map = new HashMap<>();
            map.put("lisi",20.0);
            map.put("wangwu",30.0);
            jedis.zadd("key1",map);

            long result = jedis.zrem("key1","zhangsan","lisi");
            System.out.println("result: " + result);

            List<Tuple> result1 = jedis.zrangeWithScores("key1",0,-1);
            System.out.println("result1: " + result1);
        }*/

        /*try (Jedis jedis = jedisPool.getResource()) {
            System.out.println("zscore 的使用");
            jedis.flushAll();

            jedis.zadd("key1",10,"zhangsan");
            Map<String,Double> map = new HashMap<>();
            map.put("lisi",20.0);
            map.put("wangwu",30.0);
            jedis.zadd("key1",map);

            Double result = jedis.zscore("key1","zhangsan");
            System.out.println("result: " + result);
        }*/

        /*try (Jedis jedis = jedisPool.getResource()) {
            System.out.println("zrank 的使用");
            jedis.flushAll();

            jedis.zadd("key1",10,"zhangsan");
            Map<String,Double> map = new HashMap<>();
            map.put("lisi",20.0);
            map.put("wangwu",30.0);
            jedis.zadd("key1",map);

            long result = jedis.zrank("key1","lisi");
            System.out.println("result: " + result);
        }*/

        /*try (Jedis jedis = jedisPool.getResource()) {
            System.out.println("zrank 的使用");
            jedis.flushAll();

            jedis.zadd("key1",10,"zhangsan");
            Map<String,Double> map = new HashMap<>();
            map.put("lisi",20.0);
            map.put("wangwu",30.0);
            jedis.zadd("key1",map);

            long result = jedis.zrank("key1","lisi");
            System.out.println("result: " + result);
        }*/

    }
}
